.class public Lorg/jboss/netty/handler/codec/http/websocketx/WebSocketServerHandshaker00;
.super Lorg/jboss/netty/handler/codec/http/websocketx/WebSocketServerHandshaker;
.source "WebSocketServerHandshaker00.java"


# static fields
.field private static final logger:Lorg/jboss/netty/logging/InternalLogger;


# direct methods
.method static constructor <clinit>()V
    .locals 1

    .prologue
    .line 51
    const-class v0, Lorg/jboss/netty/handler/codec/http/websocketx/WebSocketServerHandshaker00;

    invoke-static {v0}, Lorg/jboss/netty/logging/InternalLoggerFactory;->getInstance(Ljava/lang/Class;)Lorg/jboss/netty/logging/InternalLogger;

    move-result-object v0

    sput-object v0, Lorg/jboss/netty/handler/codec/http/websocketx/WebSocketServerHandshaker00;->logger:Lorg/jboss/netty/logging/InternalLogger;

    return-void
.end method

.method public constructor <init>(Ljava/lang/String;Ljava/lang/String;)V
    .locals 1
    .parameter "webSocketURL"
    .parameter "subprotocols"

    .prologue
    .line 63
    sget-object v0, Lorg/jboss/netty/handler/codec/http/websocketx/WebSocketVersion;->V00:Lorg/jboss/netty/handler/codec/http/websocketx/WebSocketVersion;

    invoke-direct {p0, v0, p1, p2}, Lorg/jboss/netty/handler/codec/http/websocketx/WebSocketServerHandshaker;-><init>(Lorg/jboss/netty/handler/codec/http/websocketx/WebSocketVersion;Ljava/lang/String;Ljava/lang/String;)V

    .line 64
    return-void
.end method


# virtual methods
.method public close(Lorg/jboss/netty/channel/Channel;Lorg/jboss/netty/handler/codec/http/websocketx/CloseWebSocketFrame;)Lorg/jboss/netty/channel/ChannelFuture;
    .locals 1
    .parameter "channel"
    .parameter "frame"

    .prologue
    .line 187
    invoke-interface {p1, p2}, Lorg/jboss/netty/channel/Channel;->write(Ljava/lang/Object;)Lorg/jboss/netty/channel/ChannelFuture;

    move-result-object v0

    return-object v0
.end method

.method public handshake(Lorg/jboss/netty/channel/Channel;Lorg/jboss/netty/handler/codec/http/HttpRequest;)Lorg/jboss/netty/channel/ChannelFuture;
    .locals 20
    .parameter "channel"
    .parameter "req"

    .prologue
    .line 114
    sget-object v15, Lorg/jboss/netty/handler/codec/http/websocketx/WebSocketServerHandshaker00;->logger:Lorg/jboss/netty/logging/InternalLogger;

    invoke-interface {v15}, Lorg/jboss/netty/logging/InternalLogger;->isDebugEnabled()Z

    move-result v15

    if-eqz v15, :cond_0

    .line 115
    sget-object v15, Lorg/jboss/netty/handler/codec/http/websocketx/WebSocketServerHandshaker00;->logger:Lorg/jboss/netty/logging/InternalLogger;

    const-string v16, "Channel %s WS Version 00 server handshake"

    const/16 v17, 0x1

    move/from16 v0, v17

    new-array v0, v0, [Ljava/lang/Object;

    move-object/from16 v17, v0

    const/16 v18, 0x0

    invoke-interface/range {p1 .. p1}, Lorg/jboss/netty/channel/Channel;->getId()Ljava/lang/Integer;

    move-result-object v19

    aput-object v19, v17, v18

    invoke-static/range {v16 .. v17}, Ljava/lang/String;->format(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v16

    invoke-interface/range {v15 .. v16}, Lorg/jboss/netty/logging/InternalLogger;->debug(Ljava/lang/String;)V

    .line 119
    :cond_0
    const-string v15, "Upgrade"

    const-string v16, "Connection"

    move-object/from16 v0, p2

    move-object/from16 v1, v16

    invoke-interface {v0, v1}, Lorg/jboss/netty/handler/codec/http/HttpRequest;->getHeader(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v16

    invoke-virtual/range {v15 .. v16}, Ljava/lang/String;->equalsIgnoreCase(Ljava/lang/String;)Z

    move-result v15

    if-eqz v15, :cond_1

    const-string v15, "WebSocket"

    const-string v16, "Upgrade"

    move-object/from16 v0, p2

    move-object/from16 v1, v16

    invoke-interface {v0, v1}, Lorg/jboss/netty/handler/codec/http/HttpRequest;->getHeader(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v16

    invoke-virtual/range {v15 .. v16}, Ljava/lang/String;->equalsIgnoreCase(Ljava/lang/String;)Z

    move-result v15

    if-nez v15, :cond_2

    .line 121
    :cond_1
    new-instance v15, Lorg/jboss/netty/handler/codec/http/websocketx/WebSocketHandshakeException;

    const-string v16, "not a WebSocket handshake request: missing upgrade"

    invoke-direct/range {v15 .. v16}, Lorg/jboss/netty/handler/codec/http/websocketx/WebSocketHandshakeException;-><init>(Ljava/lang/String;)V

    throw v15

    .line 125
    :cond_2
    const-string v15, "Sec-WebSocket-Key1"

    move-object/from16 v0, p2

    invoke-interface {v0, v15}, Lorg/jboss/netty/handler/codec/http/HttpRequest;->containsHeader(Ljava/lang/String;)Z

    move-result v15

    if-eqz v15, :cond_5

    const-string v15, "Sec-WebSocket-Key2"

    move-object/from16 v0, p2

    invoke-interface {v0, v15}, Lorg/jboss/netty/handler/codec/http/HttpRequest;->containsHeader(Ljava/lang/String;)Z

    move-result v15

    if-eqz v15, :cond_5

    const/4 v8, 0x1

    .line 128
    .local v8, isHixie76:Z
    :goto_0
    new-instance v14, Lorg/jboss/netty/handler/codec/http/DefaultHttpResponse;

    sget-object v16, Lorg/jboss/netty/handler/codec/http/HttpVersion;->HTTP_1_1:Lorg/jboss/netty/handler/codec/http/HttpVersion;

    new-instance v17, Lorg/jboss/netty/handler/codec/http/HttpResponseStatus;

    const/16 v18, 0x65

    if-eqz v8, :cond_6

    const-string v15, "WebSocket Protocol Handshake"

    :goto_1
    move-object/from16 v0, v17

    move/from16 v1, v18

    invoke-direct {v0, v1, v15}, Lorg/jboss/netty/handler/codec/http/HttpResponseStatus;-><init>(ILjava/lang/String;)V

    move-object/from16 v0, v16

    move-object/from16 v1, v17

    invoke-direct {v14, v0, v1}, Lorg/jboss/netty/handler/codec/http/DefaultHttpResponse;-><init>(Lorg/jboss/netty/handler/codec/http/HttpVersion;Lorg/jboss/netty/handler/codec/http/HttpResponseStatus;)V

    .line 130
    .local v14, res:Lorg/jboss/netty/handler/codec/http/HttpResponse;
    const-string v15, "Upgrade"

    const-string v16, "WebSocket"

    invoke-interface/range {v14 .. v16}, Lorg/jboss/netty/handler/codec/http/HttpResponse;->addHeader(Ljava/lang/String;Ljava/lang/Object;)V

    .line 131
    const-string v15, "Connection"

    const-string v16, "Upgrade"

    invoke-interface/range {v14 .. v16}, Lorg/jboss/netty/handler/codec/http/HttpResponse;->addHeader(Ljava/lang/String;Ljava/lang/Object;)V

    .line 134
    if-eqz v8, :cond_7

    .line 136
    const-string v15, "Sec-WebSocket-Origin"

    const-string v16, "Origin"

    move-object/from16 v0, p2

    move-object/from16 v1, v16

    invoke-interface {v0, v1}, Lorg/jboss/netty/handler/codec/http/HttpRequest;->getHeader(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v16

    invoke-interface/range {v14 .. v16}, Lorg/jboss/netty/handler/codec/http/HttpResponse;->addHeader(Ljava/lang/String;Ljava/lang/Object;)V

    .line 137
    const-string v15, "Sec-WebSocket-Location"

    invoke-virtual/range {p0 .. p0}, Lorg/jboss/netty/handler/codec/http/websocketx/WebSocketServerHandshaker00;->getWebSocketUrl()Ljava/lang/String;

    move-result-object v16

    invoke-interface/range {v14 .. v16}, Lorg/jboss/netty/handler/codec/http/HttpResponse;->addHeader(Ljava/lang/String;Ljava/lang/Object;)V

    .line 138
    const-string v15, "Sec-WebSocket-Protocol"

    move-object/from16 v0, p2

    invoke-interface {v0, v15}, Lorg/jboss/netty/handler/codec/http/HttpRequest;->getHeader(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v13

    .line 139
    .local v13, protocol:Ljava/lang/String;
    if-eqz v13, :cond_3

    .line 140
    const-string v15, "Sec-WebSocket-Protocol"

    move-object/from16 v0, p0

    invoke-virtual {v0, v13}, Lorg/jboss/netty/handler/codec/http/websocketx/WebSocketServerHandshaker00;->selectSubprotocol(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v16

    invoke-interface/range {v14 .. v16}, Lorg/jboss/netty/handler/codec/http/HttpResponse;->addHeader(Ljava/lang/String;Ljava/lang/Object;)V

    .line 144
    :cond_3
    const-string v15, "Sec-WebSocket-Key1"

    move-object/from16 v0, p2

    invoke-interface {v0, v15}, Lorg/jboss/netty/handler/codec/http/HttpRequest;->getHeader(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v9

    .line 145
    .local v9, key1:Ljava/lang/String;
    const-string v15, "Sec-WebSocket-Key2"

    move-object/from16 v0, p2

    invoke-interface {v0, v15}, Lorg/jboss/netty/handler/codec/http/HttpRequest;->getHeader(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v10

    .line 146
    .local v10, key2:Ljava/lang/String;
    const-string v15, "[^0-9]"

    const-string v16, ""

    move-object/from16 v0, v16

    invoke-virtual {v9, v15, v0}, Ljava/lang/String;->replaceAll(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;

    move-result-object v15

    invoke-static {v15}, Ljava/lang/Long;->parseLong(Ljava/lang/String;)J

    move-result-wide v15

    const-string v17, "[^ ]"

    const-string v18, ""

    move-object/from16 v0, v17

    move-object/from16 v1, v18

    invoke-virtual {v9, v0, v1}, Ljava/lang/String;->replaceAll(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;

    move-result-object v17

    invoke-virtual/range {v17 .. v17}, Ljava/lang/String;->length()I

    move-result v17

    move/from16 v0, v17

    int-to-long v0, v0

    move-wide/from16 v17, v0

    div-long v15, v15, v17

    long-to-int v2, v15

    .line 147
    .local v2, a:I
    const-string v15, "[^0-9]"

    const-string v16, ""

    move-object/from16 v0, v16

    invoke-virtual {v10, v15, v0}, Ljava/lang/String;->replaceAll(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;

    move-result-object v15

    invoke-static {v15}, Ljava/lang/Long;->parseLong(Ljava/lang/String;)J

    move-result-wide v15

    const-string v17, "[^ ]"

    const-string v18, ""

    move-object/from16 v0, v17

    move-object/from16 v1, v18

    invoke-virtual {v10, v0, v1}, Ljava/lang/String;->replaceAll(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;

    move-result-object v17

    invoke-virtual/range {v17 .. v17}, Ljava/lang/String;->length()I

    move-result v17

    move/from16 v0, v17

    int-to-long v0, v0

    move-wide/from16 v17, v0

    div-long v15, v15, v17

    long-to-int v3, v15

    .line 148
    .local v3, b:I
    invoke-interface/range {p2 .. p2}, Lorg/jboss/netty/handler/codec/http/HttpRequest;->getContent()Lorg/jboss/netty/buffer/ChannelBuffer;

    move-result-object v15

    invoke-interface {v15}, Lorg/jboss/netty/buffer/ChannelBuffer;->readLong()J

    move-result-wide v4

    .line 149
    .local v4, c:J
    const/16 v15, 0x10

    invoke-static {v15}, Lorg/jboss/netty/buffer/ChannelBuffers;->buffer(I)Lorg/jboss/netty/buffer/ChannelBuffer;

    move-result-object v7

    .line 150
    .local v7, input:Lorg/jboss/netty/buffer/ChannelBuffer;
    invoke-interface {v7, v2}, Lorg/jboss/netty/buffer/ChannelBuffer;->writeInt(I)V

    .line 151
    invoke-interface {v7, v3}, Lorg/jboss/netty/buffer/ChannelBuffer;->writeInt(I)V

    .line 152
    invoke-interface {v7, v4, v5}, Lorg/jboss/netty/buffer/ChannelBuffer;->writeLong(J)V

    .line 153
    invoke-interface {v7}, Lorg/jboss/netty/buffer/ChannelBuffer;->array()[B

    move-result-object v15

    invoke-static {v15}, Lorg/jboss/netty/handler/codec/http/websocketx/WebSocketUtil;->md5([B)[B

    move-result-object v15

    invoke-static {v15}, Lorg/jboss/netty/buffer/ChannelBuffers;->wrappedBuffer([B)Lorg/jboss/netty/buffer/ChannelBuffer;

    move-result-object v11

    .line 154
    .local v11, output:Lorg/jboss/netty/buffer/ChannelBuffer;
    invoke-interface {v14, v11}, Lorg/jboss/netty/handler/codec/http/HttpResponse;->setContent(Lorg/jboss/netty/buffer/ChannelBuffer;)V

    .line 166
    .end local v2           #a:I
    .end local v3           #b:I
    .end local v4           #c:J
    .end local v7           #input:Lorg/jboss/netty/buffer/ChannelBuffer;
    .end local v9           #key1:Ljava/lang/String;
    .end local v10           #key2:Ljava/lang/String;
    .end local v11           #output:Lorg/jboss/netty/buffer/ChannelBuffer;
    :cond_4
    :goto_2
    invoke-interface/range {p1 .. p1}, Lorg/jboss/netty/channel/Channel;->getPipeline()Lorg/jboss/netty/channel/ChannelPipeline;

    move-result-object v12

    .line 167
    .local v12, p:Lorg/jboss/netty/channel/ChannelPipeline;
    const-class v15, Lorg/jboss/netty/handler/codec/http/HttpChunkAggregator;

    invoke-interface {v12, v15}, Lorg/jboss/netty/channel/ChannelPipeline;->remove(Ljava/lang/Class;)Lorg/jboss/netty/channel/ChannelHandler;

    .line 168
    const-class v15, Lorg/jboss/netty/handler/codec/http/HttpRequestDecoder;

    const-string v16, "wsdecoder"

    new-instance v17, Lorg/jboss/netty/handler/codec/http/websocketx/WebSocket00FrameDecoder;

    invoke-direct/range {v17 .. v17}, Lorg/jboss/netty/handler/codec/http/websocketx/WebSocket00FrameDecoder;-><init>()V

    move-object/from16 v0, v16

    move-object/from16 v1, v17

    invoke-interface {v12, v15, v0, v1}, Lorg/jboss/netty/channel/ChannelPipeline;->replace(Ljava/lang/Class;Ljava/lang/String;Lorg/jboss/netty/channel/ChannelHandler;)Lorg/jboss/netty/channel/ChannelHandler;

    .line 170
    move-object/from16 v0, p1

    invoke-interface {v0, v14}, Lorg/jboss/netty/channel/Channel;->write(Ljava/lang/Object;)Lorg/jboss/netty/channel/ChannelFuture;

    move-result-object v6

    .line 172
    .local v6, future:Lorg/jboss/netty/channel/ChannelFuture;
    const-class v15, Lorg/jboss/netty/handler/codec/http/HttpResponseEncoder;

    const-string v16, "wsencoder"

    new-instance v17, Lorg/jboss/netty/handler/codec/http/websocketx/WebSocket00FrameEncoder;

    invoke-direct/range {v17 .. v17}, Lorg/jboss/netty/handler/codec/http/websocketx/WebSocket00FrameEncoder;-><init>()V

    move-object/from16 v0, v16

    move-object/from16 v1, v17

    invoke-interface {v12, v15, v0, v1}, Lorg/jboss/netty/channel/ChannelPipeline;->replace(Ljava/lang/Class;Ljava/lang/String;Lorg/jboss/netty/channel/ChannelHandler;)Lorg/jboss/netty/channel/ChannelHandler;

    .line 174
    return-object v6

    .line 125
    .end local v6           #future:Lorg/jboss/netty/channel/ChannelFuture;
    .end local v8           #isHixie76:Z
    .end local v12           #p:Lorg/jboss/netty/channel/ChannelPipeline;
    .end local v13           #protocol:Ljava/lang/String;
    .end local v14           #res:Lorg/jboss/netty/handler/codec/http/HttpResponse;
    :cond_5
    const/4 v8, 0x0

    goto/16 :goto_0

    .line 128
    .restart local v8       #isHixie76:Z
    :cond_6
    const-string v15, "Web Socket Protocol Handshake"

    goto/16 :goto_1

    .line 157
    .restart local v14       #res:Lorg/jboss/netty/handler/codec/http/HttpResponse;
    :cond_7
    const-string v15, "WebSocket-Origin"

    const-string v16, "Origin"

    move-object/from16 v0, p2

    move-object/from16 v1, v16

    invoke-interface {v0, v1}, Lorg/jboss/netty/handler/codec/http/HttpRequest;->getHeader(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v16

    invoke-interface/range {v14 .. v16}, Lorg/jboss/netty/handler/codec/http/HttpResponse;->addHeader(Ljava/lang/String;Ljava/lang/Object;)V

    .line 158
    const-string v15, "WebSocket-Location"

    invoke-virtual/range {p0 .. p0}, Lorg/jboss/netty/handler/codec/http/websocketx/WebSocketServerHandshaker00;->getWebSocketUrl()Ljava/lang/String;

    move-result-object v16

    invoke-interface/range {v14 .. v16}, Lorg/jboss/netty/handler/codec/http/HttpResponse;->addHeader(Ljava/lang/String;Ljava/lang/Object;)V

    .line 159
    const-string v15, "WebSocket-Protocol"

    move-object/from16 v0, p2

    invoke-interface {v0, v15}, Lorg/jboss/netty/handler/codec/http/HttpRequest;->getHeader(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v13

    .line 160
    .restart local v13       #protocol:Ljava/lang/String;
    if-eqz v13, :cond_4

    .line 161
    const-string v15, "WebSocket-Protocol"

    move-object/from16 v0, p0

    invoke-virtual {v0, v13}, Lorg/jboss/netty/handler/codec/http/websocketx/WebSocketServerHandshaker00;->selectSubprotocol(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v16

    invoke-interface/range {v14 .. v16}, Lorg/jboss/netty/handler/codec/http/HttpResponse;->addHeader(Ljava/lang/String;Ljava/lang/Object;)V

    goto :goto_2
.end method
